﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SM2TestRunner;

namespace Popups
{
    public partial class GenerateReportInputs : Form
    {
        public static string strAction;

        public GenerateReportInputs()
        {
            InitializeComponent();
        }

        public static DialogResult ShowGenerateReportInputs(string action)
        {
            GenerateReportInputs dialog = new GenerateReportInputs();
            strAction = action;
            return dialog.ShowDialog();
        }

        private void GenerateReportInputs_Load(object sender, EventArgs e)
        {
            #region DASHBOARD
            cbbDashboard.DisplayMember = "Attribute2";
            cbbDashboard.ValueMember = "Attribute1";
            try
            {
                cbbDashboard.DataSource = Repository.ServerHardDataUtil.buildDashboardsDataTable();
            }
            catch (Exception ex)
            {
                Utilities.GlobalObject.LOGGER.log("Failed to load ListBox Dashboard.CHART Utilities.GlobalInit.buildChartTypeDataTable()");
                Utilities.GlobalObject.LOGGER.log(ex.ToString());
            }
            #endregion

            #region PROFILE
            cbbProfiles.DisplayMember = "Attribute2";
            cbbProfiles.ValueMember = "Attribute1";
            try
            {
                cbbProfiles.DataSource = Repository.ServerHardDataUtil.buildProfilesDataTable();
            }
            catch (Exception ex)
            {
                Utilities.GlobalObject.LOGGER.log("Failed to load ListBox Dashboard.CHART Utilities.GlobalInit.buildProfilesDataTable()");
                Utilities.GlobalObject.LOGGER.log(ex.ToString());
            }
            #endregion

            switch (strAction)
            {
                case "GenerateReportDashboard":
                    #region
                    labelTitle.Text = "Generate Report for Dashboard";
                    cbbProfiles.Enabled = true; radioButton3.Checked = true;
                    textBoxProfileName.Enabled = false; radioButton4.Checked = false;

                    textBoxDBName.Enabled = false;radioButton4.Checked = false;
                    cbbDashboard.Enabled = true;radioButton3.Checked = true;

                    break;
                    #endregion

                default:
                    break;
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            InputDispatcher.TEST_PARAMETER = new TestParameters();

            switch (strAction)
            {
                case "GenerateReportDashboard":
                    #region
                    
                    //Dashboard Name
                    string strRemoveDBName;
                    if (textBoxDBName.Enabled)
                    {
                        strRemoveDBName = textBoxDBName.Text.Trim();
                        InputDispatcher.TEST_PARAMETER.add("DashboardName", strRemoveDBName);
                    }
                    else
                    {
                        strRemoveDBName = cbbDashboard.SelectedValue.ToString();
                        InputDispatcher.TEST_PARAMETER.add("DashboardName", strRemoveDBName);
                    }


                    //Profile Name
                    string strSelectedProfileName;
                    if (textBoxProfileName.Enabled)
                    {
                        strSelectedProfileName = textBoxProfileName.Text.Trim();
                        InputDispatcher.TEST_PARAMETER.add("Selected Profile", strSelectedProfileName);
                    }
                    else
                    {
                        strSelectedProfileName = cbbProfiles.SelectedValue.ToString();
                        InputDispatcher.TEST_PARAMETER.add("Selected Profile", strSelectedProfileName);
                    }
                    break;
                    #endregion

                default:
                    break;
            }

            this.Close();
        }

        private void btnDISCARD_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
